import React from 'react'
import { increment, decrement, ifOddIncrement, waitIncrementAction } from '../../store/slice/countSlice'
import { useDispatch, useSelector } from 'react-redux'
export default function Count() {
    const dispatch = useDispatch()
    const count = useSelector((state) => state.count.count)
    //增量处理
    const incrementHandle = () => {
        dispatch(increment(1))
    }
    //减量处理
    const decrementHandle = () => {
        dispatch(decrement(1))
    }
    //如果是奇数在增
    const ifOddDecrementHandle = () => {
        dispatch(ifOddIncrement(1))
    }
    //等会在增
    const waitDecrementHandle = () => {
        dispatch(waitIncrementAction(1))
    }
    return (
        <div>
            <h1>我是Count组件 我的值是{count}</h1>
            <div>
                <button onClick={incrementHandle}>累加</button>
                <button onClick={decrementHandle}>累减</button>
                <button onClick={ifOddDecrementHandle}>如果是奇数在加1</button>
                <button onClick={waitDecrementHandle}>等2s再加1</button>
            </div>
        </div>
    )
}
